package com.ponhu.ea2.stockcenter.provider.service.entity.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ponhu.ea2.stockcenter.provider.entity.StockDiffUploadLogs;
import com.ponhu.ea2.stockcenter.provider.mapper.StockDiffUploadLogsMapper;
import com.ponhu.ea2.stockcenter.provider.service.entity.StockDiffUploadLogsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * <p>
 * 库存差异对比文件上传记录表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-03-07
 */
@Service
public class StockDiffUploadLogsServiceImpl
        extends ServiceImpl<StockDiffUploadLogsMapper, StockDiffUploadLogs>
        implements StockDiffUploadLogsService {


    @Override
    public IPage<StockDiffUploadLogs> getPageByCreateTime(LocalDateTime createTime, int pageIndex, int pageSize) {

        LambdaQueryWrapper<StockDiffUploadLogs> queryWrapper = Wrappers
                .lambdaQuery(StockDiffUploadLogs.class)
                .orderByDesc(StockDiffUploadLogs::getCreateTime);

        if (ObjectUtils.isNotEmpty(createTime)) {
            LocalDate localDate = createTime.toLocalDate();
            LocalDateTime min = LocalDateTime.of(localDate, LocalTime.MIN);
            LocalDateTime max = LocalDateTime.of(localDate, LocalTime.MAX);
            queryWrapper.between(StockDiffUploadLogs::getCreateTime, min, max);
        }

        return page(new Page(pageIndex, pageSize), queryWrapper);
    }

}
